package net.oschina.bilbodai.common.retrofitor.support.parse;

import net.oschina.bilbodai.common.retrofitor.support.ConfigurationContext;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.w3c.dom.Element;

/**
 * @author daimao  Date: 15/12/8 Time: 下午7:30
 * @version $Id$
 */
public class ConfigTagElementParser implements BeanDefinitionParser {

    @Override
    public BeanDefinition parse(Element element, final ParserContext parserContext) {

        String scanPackages = element.getAttribute(ParserConst.ELEMENT_CONFIG_PACKAGE_SCAN_ATTR);
        BeanDefinition configurationBeanDef = ContextUtils.createSingletonDefinition(ConfigurationContext.class);
        configurationBeanDef.getPropertyValues().add(ParserConst.ELEMENT_CONFIG_PACKAGE_SCAN_ATTR, scanPackages);
        ContextUtils.registerBeanDefinition(parserContext, configurationBeanDef);
        return configurationBeanDef;
    }

}